﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using DA = class_DAO;
using EN = class_Entidad;

namespace class_BL
{
    public class RECETA_BL
    {
        public static List<EN.LST_RECETA_EN> listaReceta(EN.PARAM_RECETA_EN param)
        {
            List<EN.LST_RECETA_EN> Lista = new List<EN.LST_RECETA_EN>();
            try
            {
                Lista = DA.RECETA_DAO.listaReceta(param);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Lista;
        }

        public static int RegistroReceta(EN.RECETA_EN param)
        {
            int Id = 0;
            try
            {
                using (TransactionScope _ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Id = DA.RECETA_DAO.RegistroReceta(param);
                    EN.RECETA_INGREDIENTE_EN obj = new EN.RECETA_INGREDIENTE_EN();
                    int contador = param.ListaIngrediente.Count;
                    for (int i = 0; i < contador; i++)
                    {
                        int accion = 0;
                        obj.ID_RECETA = Id;
                        obj.ID_TPROD = param.ListaIngrediente[i].ID_TPROD;
                        obj.ID_PRODUCTO = param.ListaIngrediente[i].ID_PRODUCTO;
                        accion = DA.RECETA_DAO.RegistarIngrediente(obj);
                    }
                    _ts.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Id;
        }

        public static int EditarReceta(EN.RECETA_EN param)
        {
            int Accion = 0;
            try
            {
                using (TransactionScope _ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Accion = DA.RECETA_DAO.EditarReceta(param);
                    _ts.Complete();
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Accion;
        }

        public static int EditarEstadoReceta(EN.RECETA_EN param)
        {
            int Accion = 0;
            try
            {
                Accion = DA.RECETA_DAO.EditarEstadoReceta(param);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Accion;
        }

        public static int RegistarIngrediente(EN.RECETA_INGREDIENTE_EN param)
        {
            int Id = 0;
            try
            {
                Id = DA.RECETA_DAO.RegistarIngrediente(param);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Id;
        }

        public static int EditarIngrediente(EN.RECETA_INGREDIENTE_EN param)
        {
            int Accion = 0;
            try
            {
                Accion = DA.RECETA_DAO.EditarIngrediente(param);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Accion;
        }

        public static List<EN.LST_RECETA_INGREDIENTE_EN> ListaIngrediente(EN.PARAM_RECETA_EN param)
        {
            List<EN.LST_RECETA_INGREDIENTE_EN> Lista = new List<EN.LST_RECETA_INGREDIENTE_EN>();
            try
            {
                Lista = DA.RECETA_DAO.ListaIngrediente(param);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Lista;
        }

        public static int EliminarIngrediente(EN.RECETA_INGREDIENTE_EN param)
        {
            int Accion = 0;
            try
            {
                using (TransactionScope _ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Accion = DA.RECETA_DAO.EliminarIngrediente(param);
                    _ts.Complete();
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Accion;
        }
    }
}
